package 算法;

import org.omg.Messaging.SYNC_WITH_TRANSPORT;

public class 最大正方形 {
    public static void main(String[] args) {
        System.out.println(maximalSquare(new char[][]{{'1','0','1','0','0'},{'1','0','1','1','1'},{'1','1','1','1','1'},{'1','0','0','1','0'}}));
    }
    public static int maximalSquare(char[][] matrix) {
        int len1 = matrix.length;
        int len2 = matrix[0].length;
        for (int i = 1;i < len1; i++){
            for (int j = 1; j < len2; j++){
                if(matrix[i][j] != '0'){
                    matrix[i][j] = (char) (Math.min(matrix[i-1][j],Math.min(matrix[i][j-1],matrix[i-1][j-1]))+1);
                }
            }
        }
        char max = '0';
        for (char[] chars : matrix) {
            for (char aChar : chars) {
                max = max > aChar ? max:aChar;
            }
        }
        return (max-'0')*(max-'0');

    }
}
